<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('租车记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>单车ID：</label>
                                <input type="text" name="bikId"/>
                            </li>
                            <li>
                                <label>用户ID：</label>
                                <input type="text" name="userId"/>
                            </li>
                            <li>
                                <label>单车名称：</label>
                                <input type="text" name="bikBicycle.name"/>
                            </li>
                            <li>
                                <label>用户名称：</label>
                                <input type="text" name="sysUser.userName"/>
                            </li>
                            <li>
                                <label>租赁状态：</label>
                                <select name="rentStatus">
                                    <option value="">所有</option>
                                    <option value="1">正常出租</option>
                                    <option value="2">已归还</option>
                                </select>
                            </li>
                            <li>
                                <label>支付状态：</label>
                                <select name="payStatus">
                                    <option value="">所有</option>
                                    <option value="2">已支付</option>
                                    <option value="1">未支付</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="admin:record:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="admin:record:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('admin:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('admin:record:remove')}]];
        var prefix = ctx + "admin/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "租车记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'recordId',
                    title: '租车记录唯一标识',
                    visible: false
                },
                {
                    field: '',
                    title: '租赁状态',
                    formatter: function (value, row, index) {
                        if (row.endTime == null) {
                            return '<strong>正在出租...</strong>';
                        } else if (row.endTime != null) {
                            return '<strong>已归还</strong>';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        if (row.endTime == null) {
                            return {
                                css: {
                                    'color': '#f88513'
                                }
                            };
                        } else if (row.endTime != null) {
                            return {
                                css: {
                                    'color': '#008018'
                                }
                            };
                        }
                    }
                },
                {
                    field: 'bikId',
                    title: '单车ID'
                },
                {
                    field: 'bikBicycle.name',
                    title: '单车名称',
                    formatter: function(value, row, index) {
                        return '<strong>'+ row.bikBicycle.name +'</strong>';
                    }
                },
                {
                    field: 'userId',
                    title: '用户ID'
                },
                {
                    field: 'sysUser.userName',
                    title: '用户名称',
                    formatter: function(value, row, index) {
                        return '<strong>'+ row.sysUser.userName +'</strong>';
                    }
                },
                {
                    field: 'startTime',
                    title: '租车起始时间'
                },
                {
                    field: 'endTime',
                    title: '租车终止时间'
                },
                {
                    field: 'price',
                    title: '总价',
                    formatter: function(value, row, index) {
                        if(row.price!=null){
                            var actions = [];
                            actions.push('￥'+row.price);
                            return actions.join('');
                        }
                    }
                },
                {
                    field: '',
                    title: '支付状态',
                    formatter: function (value, row, index) {
                        if (row.payStatus == 1) {
                            return '<strong>未支付</strong>';
                        } else if (row.payStatus == 2) {
                            return '<strong>已支付</strong>';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        if (row.payStatus == 1) {
                            return {
                                css: {
                                    'color': '#d00303'
                                }
                            };
                        } else if (row.payStatus == 2) {
                            return {
                                css: {
                                    'color': '#008018'
                                }
                            };
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.endTime == null) {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="returnBik(\'' + row.recordId + '\')"><i class="fa fa-share"></i></a> ');//归还
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.recordId + '\')"><i class="fa fa-remove"></i></a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 单车记录-归还 */
        function returnBik(recordId) {
            $.modal.confirm("确认要归还车辆吗？", function() {
                $.operate.post(prefix + "/returnBik", { "recordId": recordId});
            })
        }
    </script>
</body>
</html>